<?php
namespace app\plugins\oss_1jian;

use think\Controller;
use app\plugins\oss_1jian\service\OssService;
use app\service\PluginsService;
use app\plugins\oss_1jian\service\QiniuService;
use app\plugins\oss_1jian\service\TencentService;
/**
 * 商品图片保存到阿里云oss - 钩子入口
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Hook extends Controller
{

    // 应用响应入口
    public function run($params = [])
    {
      
       
        // 是否控制器钩子
        // is_backend 当前为后端业务处理
        // hook_name 钩子名称
        if(isset($params['is_backend']) && $params['is_backend'] === true && !empty($params['hook_name']))
        {
            // 参数一   描述
            // 参数二   0 为处理成功, 负数为失败
            // 参数三   返回数据
          
 // 当前模块/控制器/方法
 $module_name = strtolower(request()->module());
 $controller_name = strtolower(request()->controller());
 $action_name = strtolower(request()->action());

 // 页面参数
 $input = input();

 $OsscConfig=array();
 $ret = PluginsService::PluginsData('oss_1jian', [], false);

 if($ret['code'] == 0)
 {
  $OsscConfig= $ret['data'];
 }

 $ret = '';

//假如是oss
 if(isset($OsscConfig["storage_type"]) && $OsscConfig["storage_type"]=="oss" )
 {
 $os=new OssService();
 switch($params['hook_name'])
 {
     case 'plugins_service_attachment_handle_begin' :
      $os->upload_oss($params);
         break;
case 'plugins_service_attachment_delete_success':
$os->del_oss($params);
case 'plugins_service_attachment_handle_end':
$os->upload_oss_end($params);
break;
    
 }
 }
//假如是qiniu
if(isset($OsscConfig["storage_type"]) && $OsscConfig["storage_type"]=="qiniu" )
{
 
$os=new QiniuService();

switch($params['hook_name'])
{
    case 'plugins_service_attachment_handle_begin' :
     $os->upload_qiniu($params);
        break;
case 'plugins_service_attachment_delete_success':
$os->del_qiniu($params);
case 'plugins_service_attachment_handle_end':
$os->upload_qiniu_end($params);
break;
   
}
}
//假如是tencent
if(isset($OsscConfig["storage_type"]) && $OsscConfig["storage_type"]=="tencent" )
{

$os=new TencentService();

switch($params['hook_name'])
{
    case 'plugins_service_attachment_handle_begin' :
     $os->upload_tencent($params);
        break;
case 'plugins_service_attachment_delete_success':
$os->del_tencent($params);
case 'plugins_service_attachment_handle_end':
$os->upload_tencent_end($params);
break;
   
}
}
 return $ret;
   //         return DataReturn('返回描述', 0);

        // 默认返回视图
        } else {
            return 'hello world!';
        }
    }
}
?>